package com.example.testapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;



/**
 * @author Administrator
 */
public class ButtonActivity extends AppCompatActivity {

    protected CheckBox buttonCheck;
    protected Button blueButton;
    protected Button redButton;

    protected String str;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button);


        buttonCheck = findViewById(R.id.buttonCheck);
        blueButton = findViewById(R.id.blueButton);
        redButton = findViewById(R.id.redButton);


        buttonCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (buttonCheck.isChecked()){
                    blueButton.setEnabled(false);
                    str = "Disable";
                    blueButton.setText(str);
                    redButton.setEnabled(true);
                }
                else {
                    blueButton.setEnabled(true);
                    str = "Normal";
                    blueButton.setText(str);
                    redButton.setEnabled(false);
                }
            }
        });

        blueButton.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                int action = motionEvent.getAction();
                if (action == MotionEvent.ACTION_DOWN){
                    str = "Press";
                    blueButton.setText(str);
                }
                else {
                    str = "Normal";
                    blueButton.setText(str);
                }
                return false;
            }

        });

    }
}
